package avicit.bdp.dds.api.controller;

import avicit.bdp.dds.api.dto.FunctionDTO;
import avicit.bdp.dds.api.service.FunctionService;
import avicit.bdp.dds.dao.entity.FunctionCondition;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * spark函数管理REST接口
 */
@RestController
@Api(tags = "spark函数管理REST接口")
@RequestMapping("/api/bdp/dds/phm/function")
public class FunctionRest {
    @Autowired
    private FunctionService functionService;

    /**
     * 获取spark函数树结构
     */
    @ApiOperation(value = "获取spark函数树结构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型", dataType = "String"),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String")
    })
    @GetMapping("/getFunctionTree")
    public ResponseMsg<List<FunctionDTO>> getFunctionTree(@RequestParam(value = "type") String type,
                                                          @RequestParam(value = "name") String name) {
        ResponseMsg<List<FunctionDTO>> responseMsg = new ResponseMsg<>();
        List<FunctionDTO> result = functionService.getFunctionTree(type,name);
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

    /**
     * 函数校验
     */
    @PostMapping("/validateFunction")
    @ApiOperation(value = "校验函数")
    public ResponseMsg<Boolean> validateFunction(@RequestBody FunctionCondition functionCondition) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(functionService.validateFunction(functionCondition));
        return responseMsg;
    }
}
